#!/bin/bash

# this is executed in the docker fpm image
set -e
cd /build

# add SNAPSHOT if it was requested
VERSION={{.version}}
if [ "$SNAPSHOT" = "yes" ]; then
    VERSION="${VERSION}-SNAPSHOT"
fi

mkdir /${BEAT_NAME:-beats}-dashboards-${VERSION}
cp -a dashboards/. /${BEAT_NAME:-beats}-dashboards-${VERSION}/
echo "$BUILDID" > /${BEAT_NAME:-beats}-dashboards-${VERSION}/.build_hash.txt

mkdir -p upload
zip -r upload/${BEAT_NAME:-beats}-dashboards-${VERSION}.zip /${BEAT_NAME:-beats}-dashboards-${VERSION}
echo "Created upload/${BEAT_NAME:-beats}-dashboards-${VERSION}.zip"

cd upload
sha1sum ${BEAT_NAME:-beats}-dashboards-${VERSION}.zip | awk '{print $1;}' > ${BEAT_NAME:-beats}-dashboards-${VERSION}.zip.sha1
echo "Created upload/${BEAT_NAME:-beats}-dashboards-${VERSION}.zip.sha1"
